package com.nlp.trie.statemachine;

import java.util.LinkedList;
/**
 * 状态
 * @author ygsong.abcft
 *
 */
public class State {
	
	private static int nextId = 0;
	public int id = nextId++;//状态编号
	private String label = "";//名称
	
	private LinkedList<Transition> transitions = new LinkedList<Transition>();
	private boolean finalState = false;
	
	public State() {
	}

	public String getLabel() {
		return label;
	}
	public LinkedList<Transition> getTransitions() {
		return transitions;
	}
	public boolean isFinal() {
		return finalState;
	}
	
	public void setLabel(String l) {
		this.label = l;
	}
	
	public void setFinal(boolean b) {
		this.finalState = b;
	}
	
	@Override
	public boolean equals(Object obj) {

		if (!(obj instanceof State)) {
			return false;
		}
		State state = (State) obj;
		return this.id == state.id;
	}
	
	@Override
	public int hashCode() {
		int hash = 3;
		hash = 97*hash+this.id;
		return hash;
	}
	
	@Override
	public String toString() {
		return label;
	}
	
	public int compareTo(State o) {
		int otherid = o.id;
		if (id < otherid) {
			return -1;
		}
		if (id > otherid) {
			return 1;
		}
		return 0;
	}
}
